#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using pii = pair<int, int>;
#define rep(i, a, b) for (int i = (a); i <= (b); i++)
#define per(i, a, b) for (int i = (a); i >= (b); i--)
#define endl '\n'
const int N = 35;

int n, m, k;
bool vis[N * N];
map<string, int> pos;

int get_cell(int x) {
  rep(i, x, n * m) if (!vis[i]) return i;
  return -1;
}
void solve() {
  cin >> n >> m >> k;
  string op, id;
  int x, y;
  while (k--) {
    cin >> op;
    if (op == "+1") {
      cin >> x >> y >> id;
      x = get_cell((x - 1) * m + y);
      if (x > 0) {
        pos[id] = x;
        vis[x] = 1;
      }
    } else {
      cin >> id;
      if (pos.count(id)) {
        x = pos[id];
        pos.erase(id);
        vis[x] = 0;
        cout << (x - 1) / m + 1 << ' ' << (x - 1) % m + 1 << endl;
      } else {
        cout << -1 << ' ' << -1 << endl;
      }
    }
  }
  return;
}
int main() {
  freopen("input.txt", "r", stdin);
  freopen("output.txt", "w", stdout);
  ios::sync_with_stdio(0), cin.tie(0), cout.tie(0);
  int t;
  t = 1;
  while (t--) solve();
  return 0;
}